﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure;

namespace DeepTime.DataSources.DL
{
    /// <summary>
    /// Generic service context for IDataModel derivitives
    /// </summary>
    /// <typeparam name="T">Derivitave of IDataModel</typeparam>
    public class AzureTableServiceContext<T> : TableServiceContext where T : TableServiceEntity
    {
        #region Class Members

        private string _TableName;

        #endregion Class Members

        #region Constructors

        public AzureTableServiceContext(string baseAddress, StorageCredentials credentials, string tableName)
            : base(baseAddress, credentials)
        {
            _TableName = tableName;
            this.ResolveType = this.ResolveEntityType;
        }

        #endregion Constructors

        #region Properties

        public string TableName
        {
            get
            {
                return _TableName;
            }
        }

        public IQueryable<T> Table
        {
            get
            {
                return base.CreateQuery<T>(TableName);
            }
        }

        #endregion Properties

        #region Methods

        public Type ResolveEntityType(string Name)
        {
            return typeof(T);
        }

        #endregion Methods
    }
}